using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;

namespace Map2.Simul
{
    class Simulation
    {
        private List<user> users = new List<user>();
        private Map map;
        private Thread myThread;

        public Simulation(Map map)
        {
            this.map = map;        
            myThread = new Thread(new ThreadStart(avance));
        }

        public void start()
        {    
            myThread.Start();
        }

        public void stop()
        {
            myThread.Abort();
            users = new List<user>();
            map.getMapPanel().drawUser(users);

        }

        public void avance()
        {
            int i = 0;
            Random rnd = new Random();
            while (i < 100)
            {
                users.Add(new user(map.getBuildings(), map.getSize().Width,map.getSize().Height, rnd.Next(10)));
                i++;
            }
            i = 0;
            while (i < 1000)
            {
                Thread.Sleep(10);
                foreach (user u in users)
                    u.nextCoordinate();
                map.getMapPanel().drawUser(users);
                i++;
            }
        }

        /*private void mapPanel_Paint()
        {
            base.mapPanel_Paint(sender, e);
            Bitmap bmp = new Bitmap(this.Width, this.Height);
            Graphics g = Graphics.FromImage(bmp);
            g.SmoothingMode = SmoothingMode.AntiAlias;
            foreach (user u in users)
                u.draw(g);
            e.Graphics.DrawImage(bmp, new Rectangle(0, 0, (int)(bmp.Size.Width * zoom), (int)(bmp.Size.Height * zoom)));
            bmp.Dispose();
        }*/
    }
}
